package com.cddx.logistics.service.impl;

import com.cddx.logistics.domain.vo.MaterialInOutStatisticsVo;
import com.cddx.logistics.mapper.*;
import com.cddx.logistics.service.MaterialInOutStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class MaterialInOutStatsServiceImpl implements MaterialInOutStatsService {

    private final CableStatisticsMapper cableMapper;
    private final TransformerStatisticsMapper transformerMapper;
    private final WireStatisticsMapper wireMapper;
    private final NewMaterialSummaryMapper newMaterialMapper;

    @Autowired
    public MaterialInOutStatsServiceImpl(
            CableStatisticsMapper cableMapper,
            TransformerStatisticsMapper transformerMapper,
            WireStatisticsMapper wireMapper,
            NewMaterialSummaryMapper newMaterialMapper) {

        this.cableMapper = cableMapper;
        this.transformerMapper = transformerMapper;
        this.wireMapper = wireMapper;
        this.newMaterialMapper = newMaterialMapper;
    }

    @Override
    public List<MaterialInOutStatisticsVo> getMaterialInOutStats(
            String type, String materialName, String materialCode) {

        // 参数校验
        if (type == null) {
            throw new IllegalArgumentException("物料类型不能为空");
        }

        // 根据类型路由查询
        switch (type.toLowerCase()) {
            case "cable":
                return cableMapper.selectCableInOutStats(materialName, materialCode);
            case "transformer":
                return transformerMapper.selectTransformerInOutStats(materialName, materialCode);
            case "wire":
                return wireMapper.selectWireInOutStats(materialName, materialCode);
            case "new":
                return newMaterialMapper.selectNewMaterialInOutStats(materialName, materialCode);
            default:
                throw new IllegalArgumentException("不支持的物料类型: " + type);
        }
    }
}